<?

class Vakanz_Attribute extends Vakanz_CRM_Db_Table_Row {
	protected $_prefix = 'attribute';

	function isExisting() {
		return false;
	}
	public function save() {
		if ($this->offsetGet(current($this->getTable()->info('primary'))) > 0) {
			$this->attribute_valid_till = date('Y-m-d H:i:s');
			$this->attribute_status = 3;
			$data = $this->toArray();
			parent::save();
			unset($data[$this->_prefix.'_autoid']);
			unset($data[$this->_prefix.'_valid_till']);
			unset($data[$this->_prefix.'_valid_from']);
			unset($data[$this->_prefix.'_status']);
			$attribute = $this->getTable()->createRow($data);
			$attribute_autoid = $attribute->save();
			return $attribute_autoid;
		} else {
			if (empty($this->attribute_id)) {
				$this->attribute_id = $this->getTable()->getNewId($this->_prefix.'_id');
			}
			return parent::save();
		}
	}

}